﻿#region License
//
// Copyright 2009 Nicholas Hadfield
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
//
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Silverfly
{
    /// <summary>
    /// A publish/subscribe event bus.
    /// </summary>
    public interface IBus
    {
        /// <summary>
        /// Publish a notification onto the event bus.
        /// </summary>
        /// <typeparam name="TNotification">Specifies the <see cref="System.Type"/> of the notification to be published.</typeparam>
        /// <param name="sender">Identifies the sender of the notification.</param>
        /// <param name="notification">The notification to be published.</param>
        void Publish<TNotification>(object sender, TNotification notification) where TNotification : class;

        /// <summary>
        /// Subscribe to notifications of type <typeparamref name="TNotification"/>.
        /// </summary>
        /// <typeparam name="TNotification">Specifies the <see cref="System.Type"/> of the notifications to be handled.</typeparam>
        /// <param name="handler">The handler for the notifications.</param>
        void Subscribe<TNotification>(Action<object, TNotification> handler) where TNotification : class;

        /// <summary>
        /// Unsubscribe handler from notifications of type <typeparamref name="TNotification"/>.
        /// </summary>
        /// <typeparam name="TNotification">Specifies the <see cref="System.Type"/> of the notifications from which to remove the handler.</typeparam>
        /// <param name="handler">The handler to be removed.</param>
        void Unsubscribe<TNotification>(Action<object, TNotification> handler) where TNotification : class;
    }
}
